package project.dade.cn.bst.manager;

import android.app.Application;
import android.content.Context;
import android.content.res.Resources;

import com.umeng.socialize.PlatformConfig;

import java.util.concurrent.TimeUnit;

import cn.jpush.android.api.JPushInterface;
import project.dade.cn.bst.network.OkHttpClientManager;
import project.dade.cn.bst.utils.CrashHandler;
import project.dade.cn.bst.utils.SharePreferenceUtil;

/**
 * Created by vain zhou on 2015/9/14.
 */
public class AppApplication extends Application {
    private static String TAG = AppApplication.class.getSimpleName();
    public static final String SP_FILE_NAME = "su_app";

    private Context appContext;
    //保存数据文件
    private SharePreferenceUtil mSpUtil;
    public static AppApplication mInstance;

    static Resources _resource;
    static Context _context;

    public static AppApplication getInstance() {
        return mInstance;
    }

    public static synchronized AppApplication context() {
        return (AppApplication) _context;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        appContext = getApplicationContext();
        _context = getApplicationContext();
        _resource = _context.getResources();
        mInstance = this;
        ApiConfig.isApiVersionType =true; //设置应用版本类型（正式/测试）
//        CrashHandler crashHandler = CrashHandler.getInstance();
//        crashHandler.setCustomCrashHanler(getApplicationContext());
//        initImageLoader(getApplicationContext());// 初始化ImageLoader
        OkHttpClientManager.getInstance().getOkHttpClient().setConnectTimeout(100000, TimeUnit.MILLISECONDS);
//       CrashHandler crashHandler=CrashHandler.getInstance();
//        crashHandler.init(getApplicationContext());
        initSharePreData();// 初始化share数据
//        BugtagsOptions options = new BugtagsOptions.Builder().
//                trackingLocation(true).//是否获取位置
//                trackingCrashLog(true).//是否收集crash
//                trackingConsoleLog(true).//是否收集console log
//                trackingUserSteps(true).//是否收集用户操作步骤
//                versionName("1.0.1").//自定义版本名称
//                versionCode(10).//自定义版本号
//                build();
//        Bugtags.start("1e76010966db5ecf1fac0d918e6ee9f3", this, Bugtags.BTGInvocationEventNone, options);
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
        PlatformConfig.setWeixin("wxb843f4731d637c2e","aa21f1b451a73d6997dcfcc2a2f42b37");
    }

    private void initSharePreData() {
        mSpUtil = new SharePreferenceUtil(this, SP_FILE_NAME);

    }
    public synchronized SharePreferenceUtil getSpUtil() {
        if (mSpUtil == null)
            mSpUtil = new SharePreferenceUtil(this, SP_FILE_NAME);
        return mSpUtil;
    }

//    /** 初始化ImageLoader */
//    public static void initImageLoader(Context context) {
//        File cacheDir = StorageUtils.getOwnCacheDirectory(context,
//                "hzapp/Cache");// 获取到缓存的目录地址
//        Log.d("cacheDir", cacheDir.getPath());
//        // 创建配置ImageLoader(所有的选项都是可选的,只使用那些你真的想定制)，这个可以设定在APPLACATION里面，设置为全局的配置参数
//        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
//                context)
//                // default = device screen dimensions
//                // 线程池内加载的数量
//                .threadPoolSize(3).threadPriority(Thread.NORM_PRIORITY - 2)
//                .memoryCache(new WeakMemoryCache())
//                .denyCacheImageMultipleSizesInMemory()
//                        //	.discCacheFileNameGenerator(new Md5FileNameGenerator())
//                        // 将保存的时候的URI名称用MD5 加密
//                .tasksProcessingOrder(QueueProcessingType.LIFO)
//                .discCache(new UnlimitedDiscCache(cacheDir))// 自定义缓存路径
//                        // .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
//                .writeDebugLogs() // Remove for release app
//                .build();
//        // Initialize ImageLoader with configuration.
//        ImageLoader.getInstance().init(config);// 全局初始化此配置
//    }

}
